package com.ruoyi.web.controller.credit;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.credit.domain.ContractPaySuppliers;
import com.ruoyi.credit.service.IContractPaySuppliersService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支出类合同合约方关系Controller
 *
 * @author zhulei
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/credit/contractSuppliers")
public class ContractPaySuppliersController extends BaseController
{
    private String prefix = "credit/contractSuppliers";

    @Autowired
    private IContractPaySuppliersService contractPaySuppliersService;

    @RequiresPermissions("credit:contractSuppliers:view")
    @GetMapping()
    public String contractSuppliers()
    {
        return prefix + "/contractSuppliers";
    }

    /**
     * 查询支出类合同合约方关系列表
     */
    @RequiresPermissions("credit:contractSuppliers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ContractPaySuppliers contractPaySuppliers)
    {
        startPage();
        List<ContractPaySuppliers> list = contractPaySuppliersService.selectContractPaySuppliersList(contractPaySuppliers);
        return getDataTable(list);
    }

    /**
     * 导出支出类合同合约方关系列表
     */
    @RequiresPermissions("credit:contractSuppliers:export")
    @Log(title = "支出类合同合约方关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ContractPaySuppliers contractPaySuppliers)
    {
        List<ContractPaySuppliers> list = contractPaySuppliersService.selectContractPaySuppliersList(contractPaySuppliers);
        ExcelUtil<ContractPaySuppliers> util = new ExcelUtil<ContractPaySuppliers>(ContractPaySuppliers.class);
        return util.exportExcel(list, "支出类合同合约方关系数据");
    }

    /**
     * 新增支出类合同合约方关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存支出类合同合约方关系
     */
    @RequiresPermissions("credit:contractSuppliers:add")
    @Log(title = "支出类合同合约方关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ContractPaySuppliers contractPaySuppliers)
    {
        return toAjax(contractPaySuppliersService.insertContractPaySuppliers(contractPaySuppliers));
    }

    /**
     * 修改支出类合同合约方关系
     */
    @RequiresPermissions("credit:contractSuppliers:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ContractPaySuppliers contractPaySuppliers = contractPaySuppliersService.selectContractPaySuppliersById(id);
        mmap.put("contractPaySuppliers", contractPaySuppliers);
        return prefix + "/edit";
    }

    /**
     * 修改保存支出类合同合约方关系
     */
    @RequiresPermissions("credit:contractSuppliers:edit")
    @Log(title = "支出类合同合约方关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ContractPaySuppliers contractPaySuppliers)
    {
        return toAjax(contractPaySuppliersService.updateContractPaySuppliers(contractPaySuppliers));
    }

    /**
     * 删除支出类合同合约方关系
     */
    @RequiresPermissions("credit:contractSuppliers:remove")
    @Log(title = "支出类合同合约方关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(contractPaySuppliersService.deleteContractPaySuppliersByIds(ids));
    }
}
